﻿namespace NEvoWeb.Modules.NB_Store
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections.Specialized;
    using System.Reflection;
    using System.Runtime.CompilerServices;

    public abstract class RequestFormWrapper
    {
        public RequestFormWrapper()
        {
        }

        public RequestFormWrapper(NameValueCollection requestForm)
        {
            this.LoadRequestForm(requestForm);
        }

        public void LoadRequestForm(NameValueCollection requestForm)
        {
            foreach (PropertyInfo info in this.GetType().GetProperties())
            {
                string str = requestForm[info.Name];
                if (str == null)
                {
                    goto Label_0127;
                }
                object objectValue = null;
                try
                {
                    switch (info.PropertyType.Name)
                    {
                        case "String":
                            objectValue = str;
                            goto Label_0109;

                        case "Int32":
                            objectValue = RuntimeHelpers.GetObjectValue(Convert.ToInt32(str));
                            goto Label_0109;

                        case "Boolean":
                            objectValue = RuntimeHelpers.GetObjectValue(Convert.ToBoolean(str));
                            break;

                        case "Decimal":
                            objectValue = RuntimeHelpers.GetObjectValue(Convert.ToDecimal(str));
                            break;
                    }
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    ProjectData.ClearProjectError();
                }
            Label_0109:
                if (objectValue != null)
                {
                    info.SetValue(this, RuntimeHelpers.GetObjectValue(objectValue), null);
                }
            Label_0127:;
            }
        }
    }
}

